(function ($) {
	$.selfList = function () {
		return {
			init: function(){
				this.listener();
				this.initLayui();
				this.courseSelflist();
				this.unitSelflist();
			},
			/**
			 * 添加各按钮所需要的监听事件
			 */
			listener: function(){

			},

			initLayui: function(){
				layui.use(['layer','form','element'], function(){
	            	var $ = layui.jquery, layer = layui.layer, form = layui.form,element = layui.element;
					form.render('checkbox');
					//全选
            	});
			},
			courseSelflist: function(){
				var submitData = {
                    page: 0,
					pageSize:1000,
					token:User.token
				};
                updateObject(Doman.url+Doman.courseSelflist, false, JSON.stringify(submitData), function (result) {
					if(result.code == "200"&&result.courseList.length>0){
						var html="";
						$.each(result.courseList,function(i,data){
							html+='<div class="layui-colla-item">'
								+ '    <h2 class="layui-colla-title">'
								+ '    		<span>'+data.title+'</span>'
								+ '    		<span>创建人：'+data.creater+'</span>'
								+ '    		<span>共'+data.authRange+'讲</span>'
								+ '    		<span>'+data.edition+'-'+data.grade+'-'+data.subject+'</span>'
								+ '    </h2>'
								+ '    <div class="layui-colla-content '+(i==0?"layui-show":"")+'">';
							var courseDetail = {
								courseId: data.courseId,
								token:User.token
							};
							updateObject(Doman.url+Doman.courseDetail, false, JSON.stringify(courseDetail), function (result) {
								if(result.code == "200"&&result.courseDetailDTO.unitList.length>0){
									$.each(result.courseDetailDTO.unitList,function(i,data){
										html+='<div class="courseListUnit"><input data-unitid='+data.unitId+' type="radio" name="unitSel" lay-skin="primary" title="第'+(i+1)+'讲 '+data.title+'"></div>';
									});
								}
							}, function () {
                            });
							html+='</div></div>';
						});
						$(".courseList .layui-collapse").html(html);
						$.selfList.initLayui();
					}
               }, function () {
                });
			},
			unitSelflist: function(){
				var submitData = {
                    page: 0,
					pageSize:1000,
					token:User.token
				};
                updateObject(Doman.url+Doman.unitSelflist, false, JSON.stringify(submitData), function (result) {
					if(result.code == "200"&&result.unitList.length>0){
						var html="";
						$.each(result.unitList,function(i,data){
							html+='<div class="courseListUnit">'
								+ '    <input type="radio" data-unitid='+data.unitId+' name="unitSel" lay-skin="primary" title="第'+(i+1)+'讲 '+data.title+'">'
						});
						$(".unitList").html(html);
						$.selfList.initLayui();
					}
               }, function () {
                });
			}
		}
	}();
    $.selfList.init();
})(jQuery);